import {
  observable,
  action
} from 'mobx-miniprogram'
import {
  getStorage,
  setStorage
} from '@/utils/storage'
import {
  reqGetInfo
} from '@/api/user'

export const InfoStore = observable({
  token: getStorage('token') || '',
  isRegister: getStorage('isRegister') || '',
  userInfo: getStorage('userInfo') || '',
 
  setToken: action(function (token) {
    this.token = token
  }),
 
  setisRegister: action(function(isRegister){
    this.isRegister = isRegister
  }),

  setUserInfo: action(async function() {
    const res = await reqGetInfo()
    setStorage('userInfo', res.data)
    this.userInfo = res.data
  })
})